﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IronSuit.Utility
{
	public static class LogHelper
	{
		static ILog LogInterface = null;
		static bool EnableDebugger = false;
		static bool EnableInfo = true;
		static bool EnableWarn = true;
		static bool EnableError = true;
		static bool EnableFatal = true;
		/// <summary>
		/// 在程序的global启动的时候制定
		/// </summary>
		/// <param name="logInterface"></param>
		/// <param name="enableDebugger">默认false</param>
		/// <param name="enableInfo"></param>
		/// <param name="enableWarn"></param>
		/// <param name="enableError"></param>
		/// <param name="enableFatal"></param>
		public static void SetConfig(ILog logInterface, bool enableDebugger, bool enableInfo, bool enableWarn, bool enableError, bool enableFatal)
		{
			LogInterface = logInterface;
			EnableDebugger = enableDebugger;
			EnableInfo = enableInfo;
			EnableWarn = enableWarn;
			EnableError = enableError;
			EnableFatal = enableFatal;
		}
		public static void Debugger(string logger, string log)
		{
			if (EnableDebugger)
				Log(LogType.Debugger, logger, log, null);
		}
		public static void Info(string logger, string log)
		{
			if (EnableInfo)
				Log(LogType.Info, logger, log, null);
		}
		public static void Warn(string logger, string log)
		{
			if (EnableWarn)
				Log(LogType.Warn, logger, log, null);
		}
		public static void Warn(string logger, string log, Exception e)
		{
			if (EnableWarn)
				Log(LogType.Warn, logger, log, e);
		}
		public static void Error(string logger, string log)
		{
			if (EnableError)
				Log(LogType.Error, logger, log, null);
		}
		public static void Error(string logger, string log, Exception e)
		{
			if (EnableError)
				Log(LogType.Error, logger, log, e);
		}
		public static void Fatal(string logger, string log)
		{
			if (EnableFatal)
				Log(LogType.Fatal, logger, log, null);
		}
		public static void Fatal(string logger, string log, Exception e)
		{
			if (EnableFatal)
				Log(LogType.Fatal, logger, log, e);
		}
		static void Log(LogType t, string logger, string log, Exception e)
		{
			if (LogInterface != null)
			{
				LogInterface.Log(t, logger, log, e);
			}
		}
	}

	public interface ILog
	{
		void Log(LogType lt, string logger, string message, Exception ex);
	}
	public enum LogType
	{
		Debugger,
		Info,
		Warn,
		Error,
		Fatal
	}
}
